﻿using EWms.Core.Components;
using Microsoft.Extensions.Configuration;
using System.Data;

public partial class AppSettings
{
    private static IConfiguration? _configuration;

    public static IConfiguration Configuration => _configuration ?? throw new InvalidOperationException("应用程序配置未初始化");

    /// <summary>
    /// 设置应用程序配置实例。
    /// </summary>
    public static void Initialize(IConfiguration configuration)
    {
        if (_configuration != null)
        {
            throw new InvalidOperationException("应用程序配置实例已经存在，无法再次设置。");
        }

        _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration), "应用程序配置不能为空。");

    }


    public static string? SelfUrl => Configuration["SelfUrl"];
    public static JwtSetting? Jwt => Configuration.GetSection(JwtSetting.SectionName).Get<JwtSetting>();
    public static RedisSetting? Redis => Configuration.GetSection(RedisSetting.SectionName).Get<RedisSetting>();

    public static DataBaseSetting? DataBase => Configuration.GetSection(DataBaseSetting.SectionName).Get<DataBaseSetting>();
    public static string[] AllowCors => Configuration.GetSection("AllowCors").Get<string[]>() ?? Array.Empty<string>();

}